﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Windows.Media;
using Microsoft.TeamFoundation.WorkItemTracking.Client;

namespace WIAssistant
{
    /// <summary>
    /// This class wraps the <see cref="FieldDefinition"/> for the destination.
    /// </summary>
    public class DestinationField : INotifyPropertyChanged
    {
        public DestinationField(FieldDefinition destField)
        {
            DestField = destField;
            IsMapped = false;

            DragFromPile = new DestinationFieldDragSourceAdvisor(false);
        }

        /// <summary>
        /// Color that is shown to indicate if the fields is mapped or not
        /// </summary>
        public Brush ColorState
        {
            get
            {
                if (IsMapped)
                    return Brushes.Blue;
                else
                    return Brushes.Red;
            }
        }

        private bool _isMapped;

        /// <summary>
        /// True if this has been mapped
        /// </summary>
        public bool IsMapped
        {
            get { return _isMapped; }
            set
            {
                _isMapped = value;
                // Since the color depends on this.  Let the UI know it may have changed.
                OnPropertyChanged("ColorState");
            }
        }


        /// <summary>
        /// This is the actual field that is being mapped
        /// </summary>
        public FieldDefinition DestField { get; set; }

        /// <summary>
        /// When Pulling from the pile this is what is used
        /// </summary>
        public DestinationFieldDragSourceAdvisor DragFromPile { get; set; }

        /// <summary>
        /// when making a match this is what is used
        /// </summary>
        public DestinationFieldDropTargetAdvisor DropOnMatch { get; set; }

        /// <summary>
        /// When we are moving the item off a match this is the target that is used
        /// </summary>
        public DestinationFieldDropTargetAdvisor DropFromMatch { get; set; }

        /// <summary>
        /// When we are putting an item back on the pile, this is what is used.
        /// </summary>
        public DestinationFieldDropTargetAdvisor DropOnPile { get; set; }

        /// <summary>
        /// Return the name of the DestField for the ToString.
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            if (DestField != null)
                return DestField.Name;

            return base.ToString();
        }

        public event PropertyChangedEventHandler PropertyChanged;
        private void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}
